import Unit from "./unit";
import Angle from "../utils/Angle";
import Point from "../utils/Point";

export default class UnitPlayer extends Unit {

  public point: Point = new Point(0, 0);
  public angle: Angle = new Angle(0);
  public isRed: boolean = true;
  public isClockwise: boolean = true;

  public drawExcute(context2D: CanvasRenderingContext2D) {
    const isRed = this.isRed;
    context2D.fillStyle = isRed ? "red": "blue";
    context2D.beginPath();
    context2D.arc(0, 0, 7, 0, Math.PI * 2);
    context2D.fill();
    const targetPoint = this.point.Move(40, 0);
    const rotateTargetPoint = targetPoint.Rotate(this.point, this.angle.RotateAngle(180));
    context2D.fillStyle = isRed ? "blue": "red";
    context2D.beginPath();
    context2D.arc(rotateTargetPoint.X, rotateTargetPoint.Y, 6, 0, Math.PI * 2);
    context2D.fill();
    this.angle.Angle = Angle.FixedAngle(this.angle.Angle + this.game.setting.speed * (this.isClockwise ? 1 : -1));
  }

  public next() {
    this.angle.Angle = Angle.FixedAngle(this.angle.Angle + 180);
    this.isRed = !this.isRed;
  }

  public rePlay() {
    this.point = new Point(0, 0);
    this.angle = new Angle(0);
    this.isRed = true;
    this.isClockwise = true;
  }

}
